package com.zhang.common.db;

import javax.sql.DataSource;
import java.util.Map;

/**
 * IDataSourceBuilder
 *
 * @author zhangxin
 * @date 2021/7/1
 */
public interface IDataSourceBuilder {
    String DB_JDBCURL = "jdbcUrl";
    String DB_USERNAME = "username";
    String DB_PASS = "password";
    String DB_DRIVER = "driverClassName";
    String DRIVER_MYSQL = "com.mysql.jdbc.Driver";
    String DRIVER_MARIADB = "org.mariadb.jdbc.Driver";
    String DRIVER_ORACLE = "oracle.jdbc.driver.OracleDriver";
    String DRIVER_HSQLDB = "org.hsqldb.jdbcDriver";
    String DRIVER_H2 = "org.h2.Driver";

    default String getDriver(String jdbcAddress) {
        if (jdbcAddress.indexOf("mysql") != -1) {
            return "com.mysql.jdbc.Driver";
        } else if (jdbcAddress.indexOf("mariadb") != -1) {
            return "org.mariadb.jdbc.Driver";
        } else if (jdbcAddress.indexOf("oracle") != -1) {
            return "oracle.jdbc.driver.OracleDriver";
        } else if (jdbcAddress.indexOf("h2") != -1) {
            return "org.h2.Driver";
        } else {
            return jdbcAddress.indexOf("hsqldb") != -1 ? "org.hsqldb.jdbcDriver" : null;
        }
    }

    DataSource build(Map<String, String> var1);

    DataSource build();

    DataSource build(String var1);

    DataSource build(String var1, String var2, String var3, String var4, String var5);

    Map<String, String> getProps();

    void setProps(Map<String, String> var1);
}
